colorAdminApp.controller('sequenceController', function($scope,$compile,$rootScope,$http,$state,$stateParams,modalService) {
	
	$scope.easyNgPagination={
			options:{
				        currentPage:1,
				        totalCount:0,
				        pageSize:10,
			            onPageChange: function(){
			 		            	$scope.loadData();
			            }
			}
	};
	
	$scope.items=[];
	$scope.loadData=function(){
		var offset=($scope.easyNgPagination.options.currentPage-1)*$scope.easyNgPagination.options.pageSize+1;
		var entity={"name":$scope.q.name,"offset":offset,"limit":$scope.easyNgPagination.options.pageSize};
		 $(".dataTables_wrapper").block({ message:'正在加载数据，请稍等...',css: { top: '50%' } });
		$http.post('configuration/persistence/sequence/query.htm',{params:entity}).success(function(data, status, headers, config) {
			$scope.items=data.rows;
			$scope.easyNgPagination.options.totalCount=data.total;
			$(".dataTables_wrapper").unblock();
		}).error(function(data, status, headers, config) {
	    	alert(data);
        });  
	};
	
	$scope.showEditModal=function(entity){
		$scope.editEntity=entity;
		$("#editModal").modal("show");	
	};
	
	$scope.showAddModal=function(){
		$("#addModal").modal("show");	
	};
	
	$scope.entity={};
	$scope.q={"genName":""};
	
	$scope.update=function(entity){
		delete entity.createTime;
		delete entity.updateTime;
		
		$(".modal-dialog").block({message:'正在执行操作，请稍等...'});
		$http.post('configuration/persistence/sequence/update.htm',{params:entity}).success(function(data, status, headers, config) {
			$(".modal-dialog").unblock();
			modalService.showAlertModal('注意',data.message);
			if(data.status==1){
				$("#editModal").modal("hide");
				$scope.loadData();
			}
		}).error(function(data, status, headers, config) {
	    	alert(data);
        });  
	};
	
    $scope.save=function(entity){
   		$(".modal-dialog").block({message:'正在执行操作，请稍等...'});
		$http.post('configuration/persistence/sequence/add.htm',{params:entity}).success(function(data, status, headers, config) {
			$(".modal-dialog").unblock();
			modalService.showAlertModal('注意',data.message);
			if(data.status==1){
				$("#addModal").modal("hide");
				$scope.loadData();
			}
		}).error(function(data, status, headers, config) {
	    	alert(data);
        });  
	};
	
	$scope.doDelete=function(item){
		if(!confirm("确认删除 “" + item.name + "” 吗？")){
			return ;
		}
		$("body").block({ message:'正在执行操作，请稍等...',css: { top: '50%' } });
		$http.post('configuration/persistence/sequence/delete.htm',{params:{"id":item.id}}).success(function(data, status, headers, config) {
			modalService.showAlertModal('注意',data.message);
			$("body").unblock();
			if(data.status==1){
				$scope.loadData(); 
			}
		}).error(function(data, status, headers, config) {
			$("body").unblock();
	    	alert(data);
       });  
	};
	
	
    
	
    
	
});
